package gupao.one.gongcangmodle.factoryMode;

import gupao.one.gongcangmodle.factoryMode.bean.Animals;
import gupao.one.gongcangmodle.factoryMode.bean.impl.Dog;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SimpleAnimalFactory {

    public static Animals createAnimal(Class< ? extends  Animals> clazz){
        try {
            if(clazz != null) return  clazz.newInstance() ;
        } catch (InstantiationException e) {
            log.error(e.getMessage(),e.getStackTrace(),e);
        } catch (IllegalAccessException e) {
            log.error(e.getMessage(),e.getStackTrace(),e);
        }
        return  null ;
    }

    public static void main(String[] args) {
        Animals animals = SimpleAnimalFactory.createAnimal(Dog.class);
        animals.canEat();
        animals.takeAction();
    }
}
